#! /usr/bin/env python

# definition of an Infix operator class
# this recipe also works in jython
# calling sequence for the infix is either:
#  x |op| y
# or:
# x <<op>> y
                                                             
class Infix:
	def __init__(self, function):
		self.function = function

	def left(self, other):  # self op other
		return self.function(other)
	def right(self, other):  # other op self
		return Infix(lambda x, self=self, other=other: self.function(other, x))

	def __ror__(self, other):  # other | self
		return self.right(other)
	def __or__(self, other):  # self | other
		return self.left(other)

	def __rlshift__(self, other):  # other << self
		return self.right(other)
	def __rshift__(self, other):  # self >> other
		return self.left(other)

	def __call__(self, value1, value2):
		return self.function(value1, value2)
